home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / lh113src.zip / SFX.ASM < prev    next >
Assembly Source File  |  1989-05-04  |  17KB  |  864 lines

  1. page    66, 120                    ;
  2. ;$_init                        ;
  3. ;***********************************************;
  4. ;       LHarc version 1.13 (c) Yoshi 1988-89.    ;
  5. ;       self-extract module : 1989/ 5/ 4    ;
  6. ;                        ;
  7. ; HTAB = 8                    ;
  8. ;***********************************************;
  9.                         ;
  10. _TEXT    segment    byte public 'CODE'        ;
  11. _TEXT    ends                    ;
  12.                         ;
  13. DGROUP    group    _BSS                ;
  14.     assume    cs:_TEXT, ds:DGROUP        ;
  15.                         ;
  16.         public    THRESHOLD, F, N_CHAR, T    ;
  17. THRESHOLD    equ    2            ;
  18. F        equ    60            ;
  19. N_CHAR        equ    (256 - THRESHOLD + F)    ;
  20. T        equ    (N_CHAR * 2 - 1)    ;
  21. R        equ    (T - 1)            ;
  22. N        equ    1000h            ;
  23. MAX_FREQ    equ    8000h            ;
  24. CRC16        equ    0a001h            ;
  25.                         ;
  26. LzHead    struc                    ;
  27.     HeadSiz    db    ?            ;
  28.     HeadChk    db    ?            ;
  29.     HeadID    db    3 dup (?)        ;
  30.     Method    db    ?            ;
  31.         db    ?            ;
  32.     PacSiz    dw    2 dup (?)        ;
  33.     OrgSiz    dw    2 dup (?)        ;
  34.     FTime    dw    ?            ;
  35.     FDate    dw    ?            ;
  36.     FAttr    dw    ?            ;
  37.     FnLen    db    ?            ;
  38.     Fname    db    14 dup (?)        ;
  39. LzHead    ends                    ;
  40.                         ;
  41. _BSS    segment    para public 'BSS'        ;
  42.     public    freq, prnt, son            ;
  43.     public    d_len, d_code            ;
  44.     public    crctbl                ;
  45.     public    cpyhdr, outfile            ;
  46.     public    curcrc, iobuf, iolen, crcflg, orgcrc
  47.                         ;
  48. freq        dw    (T + 1) dup (?)        ;
  49. prnt        dw    (T + N_CHAR) dup (?)    ;
  50. son        dw    T dup (?)        ;
  51. d_len        db    100h dup (?)        ;
  52. d_code        db    100h dup (?)        ;
  53. crctbl        dw    100h dup (?)        ;
  54. text_buf    db    N dup (?)        ;
  55. text_ptr    dw    2 dup (?)        ;
  56. cpyhdr        LzHead    1 dup (<?>)        ;
  57. outfile        dw    1 dup (?)        ;
  58. orgcrc        dw    1 dup (?)        ;
  59. curcrc        dw    1 dup (?)        ;
  60. iobuf        dw    1 dup (?)        ;
  61. crcflg        db    1 dup (?)        ;
  62. iolen        db    1 dup (?)        ;
  63. endBBS        label    byte            ;
  64. _BSS        ends                ;
  65.                         ;
  66. _TEXT    segment    byte public 'CODE'        ;
  67.     assume    cs:_TEXT, ds:DGROUP        ;
  68.                         ;
  69.     org    0100h                ;
  70.                         ;
  71.     public    start, main            ;
  72.     public    BSSseg                ;
  73.     public    cright, chglen, crlf, space    ;
  74. start:                        ;
  75.     jmp    short main            ;
  76. BSSseg    dw    (endofcode - start + 10fh) / 10h; don't move this
  77. mes_yn    equ    space - 1            ;
  78. space    db    ' $'                ;
  79. cright    db    "LHarc's SFX 1.13S (c)Yoshi, 1989."
  80.     db    13, 10, 10, '$'            ;
  81. chglen    db    01h, 04h, 0ch, 18h, 30h        ; next byte must not be 3?h
  82. overwt    db    'Overwrite $'            ;
  83. yesno    db    '[Y/N] $'            ;
  84. memory    db    'Memory$'            ;
  85. write    db    'Write$'            ;
  86. header    db    'Header$'            ;
  87. crcmes    db    'CRC'                ;
  88. error    db    ' Error'            ;
  89. crlf    db    13, 10, '$'            ;
  90.                         ;
  91. ;-----------------------------------------------;
  92. ;    âüâCâôâïü[â`âô                ;
  93. ;-----------------------------------------------;
  94. main:                        ;
  95.     cld                    ;
  96.     mov    sp, offset start        ;
  97.     mov    bx, offset cright        ;
  98.     call    mesout                ;
  99.     mov    ax, cs                ;
  100.     add    ax, BSSseg            ;
  101.     mov    ds, ax                ;
  102.     mov    es, ax                ;
  103.     add    ax, (endBBS - freq + 0fh) / 10h    ;
  104.     cmp ax, cs:[0002h]
  105.     jBE $_1
  106.         mov    bx, offset memory    ;
  107.         jmp    errout            ;
  108. $_1:
  109. ;----------------                ;
  110. ; make CRC table                ;
  111. ;----------------                ;
  112.     mov    di, offset crctbl        ;
  113.     xor    dx, dx                ;
  114. $_2:
  115.         mov    ax, dx            ;
  116.         mov    cx, 8            ;
  117. $_4:
  118.             shr ax, 1
  119.             jNC $_6
  120.                 xor    ax, CRC16
  121. $_6:
  122.         LOOP $_4
  123. $_5:
  124.         stosw                ;
  125.     inc dl
  126.     jNZ $_2
  127. $_3:
  128. ;-------------------------            ;
  129. ; make table for position            ;
  130. ;-------------------------            ;
  131.     mov    si, offset _TEXT:chglen        ;
  132.     mov    di, offset DGROUP:d_len        ;
  133.     mov    ax, 1                ; d_len = real length - 2
  134.     mov    dx, 0020h            ;
  135. $_7:
  136.         cmp ah, cs:[si]
  137.         jNE $_9
  138.             inc    al        ;
  139.             inc    si        ;
  140.             shr    dx, 1        ;
  141. $_9:
  142.         mov    cx, dx            ;
  143. $_10:
  144.             mov    [di + d_code - d_len], ah
  145.             stosb            ;
  146.         LOOP $_10
  147. $_11:
  148.         inc    ah            ;
  149.     cmp ah, 040h
  150.     jL $_7
  151. $_8:
  152. ;-----------------------------------------------;
  153.     mov    text_ptr + 2, cs        ;
  154.     mov    text_ptr, offset _TEXT:endofcode;
  155.     jmp    mn1                ;
  156.                         ;
  157. $_12:
  158.         xor    ch, ch            ;
  159.         push    cx            ; cx = HeadSiz
  160.         mov    di, offset DGROUP:cpyhdr;
  161.         lodsw                ; ah = HeadChk
  162.         stosw                ;
  163. $_14:
  164.             sub    ah, [si]    ;
  165.             movsb            ; copy header to _BSS seg.
  166.         LOOP $_14
  167. $_15:
  168.                         ; di = end of cpyhdr
  169.         pop    cx            ;
  170.         pop    ds            ;
  171.         mov    text_ptr, si        ;
  172.         jne    errhdr            ;
  173.                         ;
  174.         mov    bx, offset DGROUP:cpyhdr.Fname
  175.         mov    dx, bx            ;
  176.         add    bl, [bx - 1]        ;
  177.         adc    bh, 0            ;
  178.                         ;
  179.         mov    ax, [bx]        ; may be CRC
  180.         mov    orgcrc, ax        ;
  181.                         ;
  182.         sub    di, bx            ; bx end of Fname
  183.         mov    word ptr crcflg, di    ; if 2, crc supported.
  184.                         ; iolen = 0 also.
  185.                         ;
  186.         mov    di, offset DGROUP:cpyhdr.HeadID    ; check ID & sum
  187.         cmp    word ptr [di], 'l-'    ;
  188.         jne    errhdr            ;
  189.         mov    ax, 2[di]        ;
  190.         xchg    al, ah            ;
  191.         sub    ax, 'h0'        ;
  192.         mov    bp, ax            ; bp = method
  193.         cmp    ax, 0001h        ;
  194.         ja    errhdr            ;
  195.         cmp    byte ptr 4[di], '-'    ;
  196.                         ;
  197.         jE $_16
  198. errhdr:                        ;
  199.             mov    bx, offset header
  200.             jmp    errout        ;
  201. $_16:
  202.                         ;
  203.         mov    ax, 1            ;
  204.         cmp    word ptr cpyhdr.FnLen, 2101h ; 01h, '!'
  205.         je    mn7            ;
  206.                         ;
  207.         mov    byte ptr [bx], ' '    ;
  208.         mov    cx, bx            ;
  209.         sub    cx, dx            ;
  210.         inc    cx            ;
  211.         push    bx            ;
  212.         mov    bx, ax            ; ax = 1
  213.         mov    ah, 40h            ;
  214.         int    21h            ; display file name
  215.         pop    bx            ;
  216.         mov    byte ptr [bx], 0    ;
  217.                         ;
  218.         mov    ax, 4300h        ; get file attr
  219.         int    21h            ;   for check existence
  220.         jc    mn5            ;
  221.                         ;
  222.         mov    bx, offset overwt    ; prompt
  223.         call    mesout            ;
  224.         call    getyn            ;
  225.         je    mn5            ;
  226.                         ;
  227.         mov    ax, cpyhdr.PacSiz    ; skip file
  228.         mov    dx, cpyhdr.PacSiz + 2    ;
  229.                         ;
  230.         call    adjust            ;
  231.         jmp    mn6            ;
  232. mn5:                        ;
  233.         mov    cl, 20h            ; ch may be 0
  234.         mov    ah, 3ch            ;
  235.         int    21h            ; create file
  236.         jNC $_17
  237.             jmp    errwrite    ;
  238. $_17:
  239. mn7:                        ;
  240.         mov    outfile, ax        ;
  241.                         ;
  242.         xor    ax, ax            ;
  243.         mov    curcrc, ax        ;
  244. ;        mov    iolen, al        ; already iolen = 0
  245.                         ;
  246.         or bp, bp
  247.         jZ $_18
  248.             call    Decode        ;
  249.         jmp short $_19
  250. $_18:
  251.             call    copyall        ;
  252. $_19:
  253.                         ;
  254. $_20:
  255.         sub iolen, 8
  256.         jL $_22
  257.             dec    word ptr text_ptr
  258.         jmp $_20
  259. $_22:
  260. $_21:
  261.         call    adjust0            ;
  262.                         ;
  263.         mov    dx, cpyhdr.FDate    ;
  264.         mov    cx, cpyhdr.FTime    ;
  265.         mov    bx, outfile        ;
  266.         cmp    bx, 1            ;
  267.         je    mn8            ;
  268.         mov    ax, 5701h        ; set date
  269.         int    21h            ;
  270.         call    close            ;
  271.                         ;
  272.         cmp crcflg, 2
  273.         jNE $_23
  274.             mov    ax, curcrc    ;
  275.             cmp    ax, orgcrc    ;
  276.             jne    errcrc        ;
  277. $_23:
  278.         jmp    mn6            ;
  279. mn8:                        ;
  280.         call    getyn            ;
  281.         jne    exit            ;
  282. mn6:                        ;
  283.         mov    bx, offset crlf        ;
  284.         call    mesout            ;
  285. mn1:                        ;
  286.         push    ds            ;
  287.         lds    si, dword ptr text_ptr    ;
  288.         mov    cl, [si]        ;
  289.     or cl, cl
  290.     jZ $_24
  291.     jmp $_12
  292. $_13:
  293. $_24:
  294.     pop    ds                ;
  295. exit:                        ;
  296.     mov    ax, 4c00h            ;
  297.     int    21h                ;
  298. resident:                    ;
  299.                         ;
  300. ;-----------------------------------------------;
  301. ;    âGâëü[Åêù¥                ;
  302. ;-----------------------------------------------;
  303.     public    errhdr, errwrite, errout    ;
  304. errcrc:                        ;
  305.     call    unlink                ;
  306.     mov    bx, offset crcmes        ;
  307.     jmp    short errout1            ;
  308.                         ;
  309. errwrite:                    ;
  310.     call    close                ;
  311.     call    unlink                ;
  312.     mov    bx, offset write        ;
  313.                         ;
  314. errout:                        ;
  315.     call    mesout                ;
  316.     mov    bx, offset error        ;
  317. errout1:                    ;
  318.     call    mesout                ;
  319.     mov    ax, 4c01h            ;
  320.     int    21h                ;
  321.                         ;
  322. ;-----------------------------------------------;
  323. ;    get 'Y' or 'N'                ;
  324. ;-----------------------------------------------;
  325. getyn    proc    near                ;
  326.     mov    bx, offset yesno        ; prompt
  327.     call    mesout                ;
  328. $_25:
  329.         mov    ah, 08h            ;
  330.         int    21h            ;
  331.         and    al, 0dfh        ;
  332.     cmp al, 'Y'
  333.     jE $_27
  334.     cmp al, 'N'
  335.     jNE $_25
  336. $_26:
  337. $_27:
  338.     mov    bx, offset mes_yn        ;
  339.     mov    cs:[bx], al            ;
  340.     call    mesout                ;
  341.     cmp    al, 'Y'                ;
  342.     ret                    ;
  343. getyn    endp                    ;
  344. ;-----------------------------------------------;
  345. ;    âoâbâtâ@é╠Åoù═                ;
  346. ;-----------------------------------------------;
  347.     public    putbuf                ;
  348. putbuf    proc    near                ;
  349.     mov    dx, offset text_buf        ;
  350.     mov    cx, di                ;
  351.     mov    bx, outfile            ;
  352.     mov    ah, 40h                ; write to file
  353.     int    21h                ;
  354.     jc    errwrite            ;
  355.     sub ax, cx
  356.     jE $_28
  357.         cmp    bx, 1            ;
  358.         jne    errwrite        ;
  359. $_28:
  360.                         ;
  361.     push    si                ;
  362.     mov    si, dx                ;
  363.     jcxz    putbuf9                ;
  364.     mov    ax, curcrc            ;
  365. $_29:
  366.         xor    al, [si]        ;
  367.         inc    si            ;
  368.         mov    bl, al            ; crc & 0xff
  369.         xor    bh, bh            ;
  370.         mov    al, ah            ; crc >> 8
  371.         xor    ah, ah            ;
  372.         shl    bx, 1            ;
  373.         xor    ax, crctbl[bx]        ;
  374.     LOOP $_29
  375. $_30:
  376.     mov    curcrc, ax            ;
  377. putbuf9:                    ;
  378.     call    adjust0                ;
  379.                         ;
  380.     pop    si                ;
  381.     cmp    outfile, 1            ;
  382.     je    return                ;
  383.     mov    ah, 02h                ;
  384.     mov    dl, '.'                ;
  385.     jmp    short int21_ret            ; int    21h
  386.                         ; ret
  387. putbuf    endp                    ;
  388.                         ;
  389. ;-----------------------------------------------;
  390. ;    âtâ@âCâïé╠ close            ;
  391. ;-----------------------------------------------;
  392.     public    close                ;
  393. close    proc    near                ;
  394.     mov    bx, outfile            ;
  395.     mov    ah, 3eh                ;
  396.     jmp    short int21_ret            ; int    21h
  397.                         ; ret
  398. close    endp                    ;
  399.                         ;
  400. ;-----------------------------------------------;
  401. ;    âtâ@âCâïé╠ìφÅ£                ;
  402. ;-----------------------------------------------;
  403.     public    unlink                ;
  404. unlink    proc    near                ;
  405.     mov    dx, offset cpyhdr.Fname        ;
  406.     mov    ah, 41h                ; unlink
  407. int21_ret:                    ;
  408.     int    21h                ;
  409. return:                        ;
  410.     ret                    ;
  411. unlink    endp                    ;
  412.                         ;
  413. ;-----------------------------------------------;
  414. ;    adjust text pointer            ;
  415. ;-----------------------------------------------;
  416. ;    dx_ax : add count            ;
  417. ;-----------------------------------------------;
  418.     public    adjust0, adjust1, adjust    ;
  419. adjust0    proc    near                ;
  420.     xor    ax, ax                ;
  421. adjust1    proc    near                ;
  422.     cwd                    ;
  423. adjust    proc    near                ;
  424.     mov    si, offset text_ptr        ;
  425.                         ;
  426.     add    word ptr [si], 10h        ;
  427.     dec    word ptr 2[si]            ;
  428.                         ;
  429.     add    ax, [si]            ;
  430.     adc    dx, 0                ;
  431.     mov    cx, ax                ;
  432.     and    cx, 000fh            ;
  433.     mov    [si], cx            ;
  434.     sub    ax, cx                ;
  435.     or    ax, dx                ;
  436.     mov    cl, 4                ;
  437.     ror    ax, cl                ;
  438.     add    2[si], ax            ;
  439.     ret                    ;
  440. adjust    endp                    ;
  441. adjust1    endp                    ;
  442. adjust0    endp                    ;
  443.                         ;
  444. ;-----------------------------------------------;
  445. ;    é╗é╠é▄é▄Åoù═                ;
  446. ;-----------------------------------------------;
  447.     public    copyall                ;
  448. copyall    proc    near                ;
  449.     xor    di, di                ;
  450. $_31:
  451.         mov    bx, offset DGROUP:cpyhdr.OrgSiz
  452.         sub    [bx], di        ;
  453.         sbb    word ptr 2[bx], 0    ;
  454.         mov    cx, N            ;
  455.         jNE $_34
  456.             mov    ax, [bx]    ;
  457.             or    ax, ax        ;
  458.             jz    cpyend        ;
  459.         cmp ax, cx
  460.         jAE $_34
  461.             mov    cx, ax        ;
  462. $_34:
  463.                         ;
  464.         push    cx            ;
  465.         mov    di, offset text_buf    ;
  466.         lds    si, dword ptr text_ptr    ;
  467.         rep    movsb            ;
  468.         push    es            ;
  469.         pop    ds            ;
  470.         pop    di            ;
  471.         call    putbuf            ;
  472.         mov    ax, di            ;
  473.         call    adjust1            ;
  474.     jmp $_31
  475. $_33:
  476. $_32:
  477. cpyend:                        ;
  478.     ret                    ;
  479. copyall    endp                    ;
  480.                         ;
  481. ;-----------------------------------------------;
  482. ;    âüâbâZü[âWé╠Åoù═            ;
  483. ;-----------------------------------------------;
  484.     public    mesout                ;
  485. mesout    proc    near                ;
  486.     push    ds                ;
  487.     push    ax                ;
  488.     push    dx                ;
  489.     push    cs                ;
  490.     pop    ds                ;
  491.     mov    dx, bx                ;
  492.     mov    ah, 09h                ;
  493.     int    21h                ;
  494.     pop    dx                ;
  495.     pop    ax                ;
  496.     pop    ds                ;
  497.     ret                    ;
  498. mesout    endp                    ;
  499.                         ;
  500. ;-----------------------------------------------;
  501. ;    û╪ì\æóé╠ì─ì\Æz                ;
  502. ;-----------------------------------------------;
  503.         public    reconst            ;
  504. reconst    proc    near                ;
  505.     push    si                ;
  506.                         ;
  507.     xor    si, si                ;
  508.     mov    di, si                ;
  509. $_35:
  510.         mov    bx, son[si]        ;
  511.         lodsw                ; freq[si]
  512.         cmp bx, bp
  513.         jB $_37
  514.             inc    ax        ;
  515.             shr    ax, 1        ;
  516.             mov    son[di], bx    ;
  517.             stosw            ; mov    freq[di], ax
  518.                         ; add    di, 2
  519. $_37:
  520.     cmp si, bp
  521.     jB $_35
  522. $_36:
  523.     xor    si, si                ;
  524. $_38:
  525.         push    si            ;
  526.         lodsw                ; freq[si]
  527.         add    ax, [si]        ; freq[bx]
  528.         mov    [di], ax        ; freq[di], ax
  529.                         ;
  530.         mov    bx, di            ;
  531. $_40:
  532.             dec    bx        ;
  533.             dec    bx        ;
  534.         cmp ax, [bx]
  535.         jB $_40
  536. $_41:
  537.         inc    bx            ;
  538.         inc    bx            ;
  539.                         ;
  540.         push    ax            ;
  541.         push    di            ;
  542.         std                ;
  543.         jmp    short rc1        ;
  544. $_42:
  545.             mov    ax, [di - 2]    ; freq[di - 2]
  546.             mov    cx, son[di - 2]    ;
  547.             mov    son[di], cx    ;
  548.             stosw            ; freq[di], ax
  549. rc1:                        ;
  550.         cmp di, bx
  551.         jA $_42
  552. $_43:
  553.         cld                ;
  554.         pop    di            ;
  555.         pop    [bx]            ; freq[bx]
  556.         pop    son[bx]            ;
  557.                         ;
  558.         lodsw                ; add    si, 2
  559.         scasw                ; add    di, 2
  560.     cmp di, bp
  561.     jB $_38
  562. $_39:
  563.     xor    si, si                ;
  564. $_44:
  565.         mov    di, son[si]        ;
  566.         mov    prnt[di], si        ;
  567.         cmp di, bp
  568.         jAE $_46
  569.             mov    prnt[di + 2], si;
  570. $_46:
  571.         lodsw                ; add    si, 2
  572.     cmp si, bp
  573.     jB $_44
  574. $_45:
  575.                         ;
  576.     pop    si                ;
  577.     ret                    ;
  578. reconst    endp                    ;
  579.                         ;
  580. ;-----------------------------------------------;
  581. ;    û╪ì\æóé╠ìXÉV                ;
  582. ;-----------------------------------------------;
  583. ;    si : prnt[c + T]            ;
  584. ;-----------------------------------------------;
  585.     public    update                ;
  586. update    proc    near                ;
  587.     or freq[R * 2], 0
  588.     jNS $_47
  589.         call    near ptr reconst    ;
  590. $_47:
  591.     mov    si, ds:prnt[si + bp]        ;
  592. $_48:
  593.         mov    di, si            ; lea    di, freq[si]
  594.         mov    ax, [di]        ;
  595.         scasw    ; inc    di        ;
  596.             ; inc    di        ;
  597.         scasw
  598.         jNE $_50
  599.             mov    cx, 0ffffh    ; must large enough
  600.             repe    scasw        ;
  601.             sub    di, 4        ; offset freq + 4
  602.                         ;
  603.             mov    bx, son[si]    ;
  604.             mov    prnt[bx], di    ;
  605.             cmp bx, bp
  606.             jAE $_51
  607.                 mov    prnt[bx + 2], di
  608. $_51:
  609.             xchg    bx, son[di]    ;
  610.             mov    prnt[bx], si    ;
  611.             cmp bx, bp
  612.             jAE $_52
  613.                 mov    prnt[bx + 2], si
  614. $_52:
  615.             mov    son[si], bx    ;
  616.                         ;
  617.             mov    si, di        ;
  618. $_50:
  619.         inc    word ptr [si]        ; freq[si]
  620.         mov    si, prnt[si]        ;
  621.     or si, si
  622.     jNZ $_48
  623. $_49:
  624.     ret                    ;
  625. update    endp                    ;
  626.                         ;
  627. ;-----------------------------------------------;
  628. ;    égétéeé╠ë≡ô╟                ;
  629. ;-----------------------------------------------;
  630.         public    DecodeChar        ;
  631. DecodeChar    proc    near            ;
  632.     push    bp                ;
  633.     mov    bp, T * 2            ;
  634.     mov    si, son[R * 2]            ;
  635.     mov    dx, DGROUP:iobuf        ;
  636.     mov    cl, DGROUP:iolen        ;
  637.     xor    ch, ch                ;
  638. $_53:
  639.         jcxz    GetBuf            ;
  640. dc2:                        ;
  641.         shr    si, 1            ;
  642.         shl    dx, 1            ;
  643.         adc    si, 0            ;
  644.         shl    si, 1            ;
  645.         mov    si, son[si]        ;
  646.         dec    cx            ;
  647.     cmp si, bp
  648.     jB $_53
  649. $_54:
  650.     mov    DGROUP:iobuf, dx        ;
  651.     mov    DGROUP:iolen, cl        ;
  652.     sub    si, bp                ;
  653.     push    si                ;
  654.     call    near ptr update            ;
  655.     pop    ax                ;
  656.     shr    ax, 1                ;
  657.     pop    bp                ;
  658.     ret                    ;
  659. DecodeChar    endp                ;
  660.                         ;
  661.     public    GetBuf                ;
  662. GetBuf:                        ;
  663.     call    getc                ;
  664.     mov    dh, al                ;
  665.     call    getc                ;
  666.     mov    dl, al                ;
  667.     mov    cl, 16                ;
  668.     jmp    short dc2            ;
  669.                         ;
  670. ;-----------------------------------------------;
  671. ;    getc                    ;
  672. ;        ax: 1 byte (return)            ;
  673. ;-----------------------------------------------;
  674.     public    getc                ;
  675. getc    proc    near                ;
  676.     push    es                ;
  677.     les    bx, dword ptr text_ptr        ;
  678.     mov    al, es:[bx]            ;
  679.     inc    text_ptr            ;
  680.     xor    ah, ah                ;
  681.     pop    es                ;
  682.     ret                    ;
  683. getc    endp                    ;
  684.                         ;
  685. ;-----------------------------------------------;
  686. ;    ôⁿù═é⌐éτéÄârâbâgé≡ô╛éΘ            ;
  687. ;-----------------------------------------------;
  688. ;    cl : n bits                ;
  689. ;-----------------------------------------------;
  690.         public    GetNBits        ;
  691. GetNBits    proc    near            ;
  692.     push    cx                ;
  693.     mov    dx, DGROUP:iobuf        ;
  694.     cmp iolen, 8
  695.     jG $_55
  696.         call    getc            ;
  697.         mov    cl, 8            ;
  698.         sub    cl, DGROUP:iolen    ;
  699.         shl    ax, cl            ;
  700.         or    dx, ax            ;
  701.         add    DGROUP:iolen, 8        ;
  702. $_55:
  703.     pop    cx                ;
  704.     mov    ax, dx                ;
  705.     shl    dx, cl                ;
  706.     mov    DGROUP:iobuf, dx        ;
  707.     sub    DGROUP:iolen, cl        ;
  708.     mov    dx, -1                ;
  709.     shr    dx, cl                ;
  710.     not    dx                ;
  711.     and    ax, dx                ;
  712.     ret                    ;
  713. GetNBits    endp                ;
  714.                         ;
  715. ;-----------------------------------------------;
  716. ;    ê╩ÆuÅεò±é╠ë≡ô╟                ;
  717. ;-----------------------------------------------;
  718.         public    DecodePosition        ;
  719. DecodePosition    proc    near            ;
  720.     mov    cx, 8                ;
  721.     call    near ptr GetNBits        ;
  722.     xchg    al, ah                ;
  723.     mov    si, ax                ;
  724.     mov    dl, d_code[si]            ;
  725.     mov    dh, 0                ;
  726.     mov    cl, 6                ;
  727.     shl    dx, cl                ;
  728.     push    dx                ;
  729.     mov    cl, d_len[si]            ; ch == 0
  730.     call    near ptr GetNBits        ;
  731.     or    ax, si                ;
  732.     rol    ax, cl                ;
  733.     and    ax, 003fh            ;
  734.     pop    dx                ;
  735.     add    ax, dx                ;
  736.     ret                    ;
  737. DecodePosition    endp                ;
  738.                         ;
  739. ;-----------------------------------------------;
  740. ;    Decode                    ;
  741. ;-----------------------------------------------;
  742.     public    Decode                ;
  743. Decode    proc    near                ;
  744.     mov    si, offset DGROUP:cpyhdr.OrgSiz    ;
  745.     lodsw                    ;
  746.     or    ax, [si]            ;
  747.     jNZ $_56
  748.         jmp    de9            ;
  749. $_56:
  750. ;----------------------------            ;
  751. ;  égétéeùpé╠û╪ì\æóé╠Åëè·ë╗            ;
  752. ;----------------------------            ;
  753.     public    StartHuff            ;
  754. StartHuff:                    ;
  755.     mov    ax, 1                ;
  756.     mov    cx, N_CHAR            ;
  757.     push    cx                ;
  758.     xor    di, di                ; mov    di, offset DGROUP:freq
  759.     rep    stosw                ;
  760.     mov    ax, T * 2            ;
  761.     xor    dx, dx                ;
  762.     pop    cx                ;
  763.     mov    di, offset DGROUP:son        ;
  764.     mov    bx, offset DGROUP:prnt[T * 2]    ;
  765. $_57:
  766.         stosw                ;
  767.         inc    ax            ; add    ax, 2
  768.         inc    ax            ;
  769.         mov    [bx], dx        ;
  770.         inc    bx            ; add    bx, 2
  771.         inc    bx            ;
  772.         inc    dx            ; add    dx, 2
  773.         inc    dx            ;
  774.     LOOP $_57
  775. $_58:
  776.                         ;
  777.     xor    si, si                ;
  778.     mov    di, N_CHAR * 2            ;
  779.     mov    cx, N_CHAR - 1            ;
  780. $_59:
  781.         mov    son[di], si        ;
  782.         mov    prnt[si], di        ;
  783.         lodsw                ; mov    ax, freq[si]
  784.         add    ax, [si]        ; add    ax, freq[si + 2]
  785.         mov    prnt[si], di        ;
  786.         stosw                ; mov    freq[di], ax
  787.         lodsw                ;
  788.     LOOP $_59
  789. $_60:
  790.     xor    ax, ax                ;
  791.     mov    iobuf, ax            ;
  792. ;    mov    iolen, al            ;
  793.     mov    DGROUP:prnt[R * 2], ax        ; prnt[R * 2], 0
  794.     dec    ax                ;
  795.     mov    [di], ax            ; freq[T * 2], -1
  796. ;----------------------------            ;
  797.                         ;
  798.     mov    al, 20h                ;
  799.     mov    cx, F                ;
  800.     mov    di, offset DGROUP:text_buf + N - F
  801.     rep    stosb                ;
  802.                         ;
  803.     xor    di, di                ;
  804.     mov    bp, N - 1            ;
  805. $_61:
  806.         push    di            ;
  807.         call    near ptr DecodeChar    ;
  808. ;        $_if                ;
  809.         or    ah, ah            ;
  810.         jnz    de1            ;
  811.             pop    di        ;
  812.             mov    cx, 1        ;
  813.             push    cx        ;
  814.             jmp    short de2    ;
  815. ;        $_else                ;
  816. de1:                        ;
  817.             push    ax        ;
  818.             call    near ptr DecodePosition
  819.             pop    cx        ;
  820.             pop    di        ;
  821.             mov    si, di        ;
  822.             sub    si, ax        ;
  823.             dec    si        ;
  824.             and    si, bp        ;
  825.             sub    cx, 255 - THRESHOLD
  826.             push    cx        ;
  827. $_63:
  828.                 mov    al, DGROUP:text_buf[si]
  829.                 inc    si    ;
  830.                 and    si, bp    ;
  831. de2:                        ;
  832.                 mov    DGROUP:text_buf[di], al
  833.                 inc    di    ;
  834.                 cmp di, bp
  835.                 jBE $_65
  836.                     push    cx
  837.                     call    putbuf
  838.                     pop    cx
  839. $_65:
  840.                 and    di, bp    ;
  841.             LOOP $_63
  842. $_64:
  843.             pop    cx        ;
  844. ;        $_elseif            ;
  845.         mov    bx, offset DGROUP:cpyhdr.OrgSiz
  846.         sub    [bx], cx        ;
  847.         pushf                ;
  848.         sbb    word ptr 2[bx], 0    ;
  849.         pop    ax            ;
  850.         lahf                ;
  851.         and    ah, al            ;
  852.         sahf                ;
  853.     jG $_61
  854. $_62:
  855.     call    putbuf                ;
  856. de9:                        ;
  857.     ret                    ;
  858. Decode    endp                    ;
  859.                         ;
  860.     public    endofcode            ;
  861. endofcode:                    ;
  862. _TEXT    ends                    ;
  863.     end    start                ;
  864.